package com.xujl.mvcbind.ui.home.view;

import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.xujl.fastlib.base.BaseView;
import com.xujl.fastlib.base.IControl;
import com.xujl.mvcbind.adapter.provider.ProviderMultiAdapter;
import com.xujl.mvcbind.databinding.FragmentComplexBinding;
import com.xujl.mvcbind.util.RefreshLayoutHelper;

import androidx.recyclerview.widget.StaggeredGridLayoutManager;


/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class ComplexFragmentView extends BaseView<FragmentComplexBinding> {
    @Override
    public void init (IControl control) {
        RefreshLayoutHelper.refreshLayoutDefaultSetting(mBind.refreshLayout);
        mBind.refreshLayout.setOnRefreshLoadMoreListener((OnRefreshLoadMoreListener) control);
        mBind.rv.setLayoutManager(new StaggeredGridLayoutManager(8, StaggeredGridLayoutManager.VERTICAL) {
            @Override
            public int getSpanCount () {
                return super.getSpanCount();
            }
        });
    }

    public void setAdapter (ProviderMultiAdapter adapter) {
        mBind.rv.setAdapter(adapter);
    }

    public void stopRefresh () {
        mBind.refreshLayout.finishRefresh();
        mBind.refreshLayout.finishLoadMore();
    }

    public void startRefresh () {
        mBind.refreshLayout.autoRefresh();
    }
}
